package com.sg.business.commons.editingsupport;

import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.swt.widgets.Shell;

import com.sg.business.model.Work;
import com.sg.widgets.commons.editingsupport.CellClickListener;
import com.sg.widgets.part.CurrentAccountContext;
import com.sg.widgets.part.RichInputDialog;

public class WorkNoteEditingSupport extends CellClickListener {


	@Override
	protected void selected(Object element, String columnId, ColumnViewer viewer) {
		Shell parent = viewer.getControl().getShell();

		Work selected = (Work) element;
		String note = selected.getNote();
		if(note == null){
			note = "";
		}
		
		RichInputDialog ip = new RichInputDialog(parent, "Note", selected.getLabel(), note);
		if(RichInputDialog.OK == ip.open()){
			note = ip.getValue();
			((Work) selected).doSetNote(note,new CurrentAccountContext());
			viewer.update(selected, null);
		}
	}

	@Override
	protected void selected(Object element, String columnId) {
		// do nothing
	}

	@Override
	protected boolean canEdit(Object element) {
		return true;
	}

}
